<?php

namespace App\Models\Recommend;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ApppageRectplData
 * @package App\Models\Recommend
 * @version July 25, 2018, 9:47 am CST
 *
 * @property \App\Models\Recommend\Pagetpl pagetpl
 * @property \App\Models\Recommend\Paneltpl paneltpl
 * @property \App\Models\Recommend\Data data
 * @property string name
 * @property string title
 * @property string subtitle
 * @property integer pagetpl_id
 * @property integer paneltpl_id
 * @property string area
 * @property integer data_id
 * @property integer resource_data_id
 * @property string onclick
 * @property string tags
 * @property string img
 * @property integer order
 */
class ApppageRectplData extends Model
{
    use SoftDeletes;

    public $table = 'apppage_rectpl_datas';

    protected $dates = ['deleted_at'];

    public $fillable = [
        // 'name',
        'title',
        'subtitle',
        'apppage_rectpl_area_id',
        'pagetpl_id',
        'paneltpl_id',
        'area',
        'data_id',
        'resource_data_id',
        'img',
        'order',
        'range',
        'tpl_id',
        'position',
        // 根据此字段判断是页面还是页间条状
        'page_mode',
        // 添加方式
        'insert_mode',
        'description'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        // 'name' => 'string',
        'title'            => 'string',
        'subtitle'         => 'string',
        'pagetpl_id'       => 'integer',
        'paneltpl_id'      => 'integer',
        'area'             => 'string',
        'data_id'          => 'integer',
        'resource_data_id' => 'integer',
        'img'              => 'string',
        'order'            => 'integer',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'area' => 'required|max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function pagetpl()
    {
        return $this->hasOne(\App\Models\Application\Pagetpl::class, 'id', 'pagetpl_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function paneltpl()
    {
        return $this->hasOne(\App\Models\Application\Paneltpl::class, 'id', 'paneltpl_id');
    }

    /**
     * 关联栏目类型
     * @return [type] [description]
     */
    public function columnType()
    {
        return $this->hasOne(\App\Models\Entity\Column\ColumnType::class, 'id', 'data_id');
    }

    /**
     * 获得此媒资的所有标签。
     */
    public function tags()
    {
        return $this->morphToMany(\App\Models\Entity\Tag\tag::class, 'tag_content');
    }
}
